use ntex::web::{self, post, Responder, ServiceConfig};

use crate::{
    model::{validate::login_valiate::LoginValidate, RespVO},
    APPLICATION_CONTEXT,
};

#[post("/system/admin/login")]
pub async fn login(param: web::types::Json<LoginValidate>) -> impl Responder {
    let token = &APPLICATION_CONTEXT
        .system_admin_auth_service
        .login(
            &param.account.clone(),
            &param.password.clone(),
            &param.code.clone(),
        )
        .await;
    RespVO::from_result(&token).resp_json()
}

pub fn system_admin_auth(cfg: &mut ServiceConfig) {
    cfg.service(login);
}
